<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="leagal_aid.bean.*,java.util.*,java.io.*" %>

<%@page import="java.text.SimpleDateFormat"%>

<%
Date d = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String now = df.format(d);
String lb = null;
if((request.getParameter("category")!=null)){
	lb = request.getParameter("category");
}else if(session.getAttribute("category")!=null){
	lb =session.getAttribute("category").toString();
}else{
	 response.sendRedirect("../backstage.jsp");
}
session.setAttribute("category", lb);
//String lb = session.getAttribute("ca")
String username=null;
	if(session.getAttribute("username")==null || session.getAttribute("username").equals("")){
		response.setCharacterEncoding("utf-8");
		PrintWriter pout = response.getWriter();
		pout.print("<script>alert('请先登录'); window.location='../login.jsp' </script>");
		pout.flush();
		pout.close();
	}
	else{
		username = session.getAttribute("username").toString();
	}

%>


<!DOCTYPE html>
<html>

<head>
	<style type="text/css">
		table {
			margin-top: 5px;
			margin-bottom: 5px;
			width: 100%;
		}

		td {
			height: 35px;
		}

		.left {
			width: 12%;
			text-align: center;
			background-color: #e6f2fe;
		}

		.form {
			border-color: #acd0d0;
		}
	</style>
	<meta charset="UTF-8">
	<title>Insert title here</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="../webupload/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" type="text/css" href="../webupload/webuploader.css">
	<link rel="stylesheet" type="text/css" href="../webupload/style.css">
</head>

<body style="padding-left: 20px; padding-right: 20px; padding-bottom: 50px;">
	<input id="picture" 	style="display: none;" />
	<div class="abroad">
		<div class="within">
			<div>
				<table class="form" border="1" cellpadding="5" cellspacing="0">
					<tbody>
						<tr>
							<td class="left">*分类：</td>
							<td class="right" style="padding-left:3px;">
								<select id="category" name="channelId" value=""
									style="height: 30px; width: 40%;">
									<option value="service" class="sel-disabled">服务领域</option>
									<option value="news" class="sel-disabled">新闻动态</option>
									<option value="classic" class="sel-disabled">经典案例</option>
									<option value="success" class="sel-disabled">成功案例</option>
									<option value="health" class="sel-disabled">卫生法研究</option>
								</select>
							</td>
							<td class="left">是否放在首页：</td>
							<td colspan="3">
								<select name="select2" id="homepage" style="margin-left:3px; height:30px;width: 100px">
									<option value="1">是</option>
									<option value="0" selected="selected">否</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="left">*标题：</td>
							<td colspan="3"><input type="text" id="title" value=""
									style="width: 99.5%; height: 30px; margin-left: 3px;">
							</td>
						</tr>
						<tr>
							<td class="left">作者：</td>
							<td><input type="text" id="author" value="赣南医学院法学系"
									style="width: 40%; height: 30px; margin-left: 3px;"></td>
							<td class="left">发布时间：</td>
							<td><input type="date" id="txtDate" value="<%=now %>"
									style="font-size: 14px; font-family: 华文黑体; margin-left: 3px; height: 30px;"></td>
						</tr>
						<tr>
							<td class="left">来源：</td>
							<td style="width: 40%;"><input id="source" value="本站原创"
									style="width: 40%; height: 30px; margin-left: 3px;"></td>
							<td class="left">链接：</td>
							<td><input type="" name="" id="link" style="width: 40%; height: 30px; margin-left: 3px;">
							</td>
						</tr>
						<tr>
							<td class="left">选择图片：</td>
							<td colspan="3">
								<div class="container">
									<div class="uploader uploader1">
										<div class="wrapper">
											<div class="file-list"></div>
										</div>
										<div class="actions-area">
											<div class="actions">
												<div class="filePicker action">选择图片</div>
												<button class="uploadFile action upload-btn disabled">上传图片</button>
											</div>
										</div>
									</div>
								</div>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<script id="container" type="text/plain" style="height: 400px;">
            这里写你的初始化内容
        </script>
        <div style="text-align: center;">
	<button id="submit" class="update_button">递交</button>
	</div>
	<script type="text/javascript" src="../ueditor/third-party/jquery-1.10.2.js"></script>
	<!-- 配置文件 -->
	<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
	<!-- 编辑器源码文件 -->
	<script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
	<!-- 实例化编辑器 -->
	<script type="text/javascript">
		var editor = UE.getEditor('container');
		$("#submit").click(function () {
			var data = editor.getContent();
			var title = $("#title").val();
			var category = $("#category").val();
			var homepage = $("#homepage").val();
			var source = $("#source").val();
			var picture = $("#picture").val();
			var author = $("#author").val();
			var txtDate = $("#txtDate").val();
			var link = $("#link").val();

			$.ajax({
				cache: true,
				type: "post",
				url: "operating_news/doadd.jsp",
				data: {
					data: data,
					title: title,
					homepage: homepage,
					source: source,
					picture: picture,
					category: category,
					author: author,
					txtDate:txtDate,
					link:link,
				},
				async: false,
				error: function (request) {
					alert("Connection error");
				},
				success: function () {
					alert("success");
					window.location.href = "news_.jsp";
				}
			});
		});
	</script>
	<script src="../webupload/jquery.min.js"></script>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="../webupload/bootstrap/js/bootstrap.min.js"></script>
	<script src="../webupload/webuploader.js"></script>
	<script src="../webupload/webuploader.support.js"></script>
	<script>
		var w1 = new WebUploaderSupport({
			server: "../FileUploadServlet",
			paste: document.body
			, swf: '/webuploader/Uploader.swf'  // swf文件所处路径
			, support: {
				uploader: ".uploader.uploader1",  //上传区域容器选择器
				fileSize: 1,  //文件总个数, -1时无限制
				/*  serverFiles: [
					 {"src":"../images/preview/1.jpg","name":"1.jpg","attrs":{"data-server-file":true,"data-delete-url":""}}
				 ],
	   */
				uploadSuccess: function (file, data) {
					var $item = this.getItem(file),
						$state = $item.find('.state');
					$item.find('.progress').hide();
					if (data.status) {  //上传成功时
						this.uploadSuccessCallbck($item, data);  //用于标识为服务端文件
						if (!$state.hasClass('success')) {
							$state.attr("class", "state success");
							$state.text('上传成功');
							$("#myimg").attr("src", data.path);
							$("#picture").attr("value", data.path);
							$item.attr("data-server-file", "true");
							$item.attr("data-delete-url", data.delurl);
							alert(data.delurl);
						}
						$item.removeClass("retry");
					} else {
						if (!$state.hasClass('error')) {
							$state.attr("class", "state error");
							$state.text('上传失败');
						}
						$item.addClass("retry");
					}
				},

				deleteServerFile: function ($item, url, deleteServerFileCallback) {
					var self = this;
					$.ajax({
						dataType: "json",
						type: "post",
						url: "../" + url,
						success: function (json) {
							deleteServerFileCallback(self, $item, json);  //通过callback执行业务操作
							//文件操作完成后重新加载选择按钮样式
							self.loadChooseFileBtnStyle();
							$("#myimg").attr("src", "");
							$("#picture").attr("value", "");
						}
					});
				},
			}
		});
	</script>
	<script>
   document.getElementById("category").value = "<%=lb%>";
</script>
</body>

</html>